package com.bkgy.controller.allprocess.controller;

import com.alibaba.fastjson.JSONObject;
import com.bkgy.commom.model.QueryDTO;
import com.bkgy.controller.allprocess.dto.*;
import com.bkgy.controller.allprocess.entity.*;
import com.bkgy.controller.allprocess.service.AllProcessService;
import com.bkgy.controller.allprocess.service.AllProcessService1870;
import com.bkgy.controller.allprocess.service.AllProcessService2150;
import com.bkgy.controller.allprocess.service.AllProcessService2280;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;

@RestController
@RequestMapping("/allprocess")
public class AllprocessController {

    @Autowired
    private AllProcessService allProcessService;

    @Autowired
    private AllProcessService2150 allProcessService2150;

    @Autowired
    private AllProcessService1870 allProcessService1870;

    @Autowired
    private AllProcessService2280 allProcessService2280;

    @Operation(summary = "1630产线成材率异常原因客户输入", description = "1630产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason1630")
    public ResultData  updateAbnormalReason1630 (@RequestBody @Valid TbYieldCal1630Entity request)
    {
        return allProcessService.updateAbnormalReason1630(request);
    }

    @Operation(summary = "2150产线成材率异常原因客户输入", description = "2150产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason2150")
    public ResultData  updateAbnormalReason2150 (@RequestBody @Valid TbYieldCal2150Entity request)
    {
        return allProcessService.updateAbnormalReason2150(request);
    }

    @Operation(summary = "1870产线成材率异常原因客户输入", description = "1870产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason1870")
    public ResultData  updateAbnormalReason1870 (@RequestBody @Valid TbYieldCglEntity request)
    {
        return allProcessService.updateAbnormalReason1870(request);
    }

    @Operation(summary = "2280产线成材率异常原因客户输入", description = "2280产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason2280")
    public ResultData  updateAbnormalReason2280 (@RequestBody @Valid TbYieldTcm2280Entity request)
    {
        return allProcessService.updateAbnormalReason2280(request);
    }

    @Operation(summary = "产品成材率全流程分析", description = "产品成材率全流程分析")
    @PostMapping("/get_allprocessproduct")
    public ResultData<AllprocessProductRate> getAllprocessProduct (@RequestBody @Valid TbAllpricessProductEntity request)
    {
        return allProcessService.getAllprocessProductRate(request);
    }

    @Operation(summary = "全流程成材率模型首页数据", description = "全流程成材率模型首页数据")
    @PostMapping("/get_allprocessindexdetails")
    public ResultData<AllProcessIndexDetails> getAllprocessIndexDetails (@RequestBody @Valid TbAllpricessIndexEntity request)
    {
        return allProcessService.getAllprocessIndexDetails(request);
    }

    @Operation(summary = "2280线全流程成材率表", description = "2280线全流程成材率明细信息")
    @PostMapping("/get_tbyieldtcm2280_detais")
    public ResultData<AllProcessTbyieldtcm2280Details> getTbyieldtcm2280Detais(@RequestBody @Valid TbYieldTcm2280Entity request)
    {
        return allProcessService.getTbyieldtcm2280(request.getHotCoilId(),request.getColdCoilId(),request.getDbegin(),request.getDend());
    }

    @Operation(summary = "2280线全流程成材率表-分页", description = "2280线全流程成材率明细信息-分页")
    @PostMapping("/get_tbyieldtcm2280_detais_page")
    public ResultData getTbyieldtcm2280_page(@RequestBody @Valid TbYieldTcm2280Entity request)
    {
        return allProcessService.getTbyieldtcm2280_page(request);
    }

    @Operation(summary = "2150线全流程成材率表", description = "2150线全流程成材率明细信息")
    @PostMapping("/get_tbyieldcal2150_detais")
    public ResultData<AllProcessTbyieldcal2150Details> getTbyieldcal2150Detais(@RequestBody @Valid TbYieldCal2150Entity request)
    {
        return allProcessService.getTbyieldcal2150(request.getColdCoilId(),request.getCalCoilId(),request.getDbegin(),request.getDend());
    }

    @Operation(summary = "2150线全流程成材率表-分页", description = "2150线全流程成材率明细信息-分页")
    @PostMapping("/get_tbyieldcal2150_detais_page")
    public ResultData getTbyieldcal2150_page(@RequestBody @Valid TbYieldCal2150Entity request)
    {
        return allProcessService.getTbyieldcal2150_page(request);
    }

    @Operation(summary = "1630线全流程成材率表", description = "1630线全流程成材率明细信息")
    @PostMapping("/get_tbyieldcal1630_detais")
    public ResultData<AllProcessTbyieldcal1630Details> getTbyieldcal1630Detais(@RequestBody @Valid TbYieldCal1630Entity request)
    {
        return allProcessService.getTbyieldcal1630(request.getColdCoilId(),request.getCalCoilId(),request.getDbegin(),request.getDend());
    }

    @Operation(summary = "1630线全流程成材率表-分页", description = "1630线全流程成材率明细信息-分页")
    @PostMapping("/get_tbyieldcal1630_detais_page")
    public ResultData get_tbyieldcal1630_page(@RequestBody @Valid TbYieldCal1630Entity request)
    {
        return allProcessService.getTbyieldcal1630_page(request);
    }

    @Operation(summary = "1870镀锌线全流程成材率表", description = "镀锌线全流程成材率明细信息")
    @PostMapping("/get_tbyieldtcm_detais")
    public ResultData<AllProcessTbyieldtcmDetais> getTbyieldtcmDetais(@RequestBody @Valid TbYieldCglEntity request)
    {
        LocalDate date = LocalDate.now();
        return allProcessService.getTbyieldtcmDetais(request.getColdCoilId(),request.getCglCoilId(),request.getDbegin(),request.getDend());
    }

    @Operation(summary = "1870镀锌线全流程成材率表-分页", description = "1870镀锌线全流程成材率表-分页")
    @PostMapping("/get_tbyieldtcm_detais_page")
    public ResultData getTbyieldtcmDetais_page(@RequestBody @Valid TbYieldCglEntity request)
    {
        return allProcessService.getTbyieldtcmDetais_page(request);
    }

    @Operation(summary = "获取报表数据", description = "获取报表数据")
    @GetMapping("/getputhead_month")
    public ResultData<AllProcessSerchDto> getputhead_month(@RequestParam(required = false,name = "timeType") String timeType)
    {
        LocalDate date = LocalDate.now();
        return allProcessService.getputhead_month(timeType, date);
    }


    @Operation(summary = "批量更改1630产线成材率异常原因客户输入", description = "批量更改1630产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason1630List")
    public ResultData updateAbnormalReason1630_List(@RequestBody JSONObject json){
        return allProcessService.updateAbnormalReason1630_List(json);
    }

    @Operation(summary = "批量更改2150产线成材率异常原因客户输入", description = "批量更改2150产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason2150List")
    public ResultData updateAbnormalReason2150_List(@RequestBody JSONObject json){
        return allProcessService.updateAbnormalReason2150_List(json);
    }


    @Operation(summary = "批量更改1870产线成材率异常原因客户输入", description = "批量更改1870产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason1870List")
    public ResultData updateAbnormalReason1870_List(@RequestBody JSONObject json){
        return allProcessService.updateAbnormalReason1870_List(json);
    }

    @Operation(summary = "批量更改2280产线成材率异常原因客户输入", description = "批量更改2280产线成材率异常原因客户输入")
    @PostMapping("/updateAbnormalReason2280List")
    public ResultData updateAbnormalReason2280_List(@RequestBody JSONObject json){
        return allProcessService.updateAbnormalReason2280_List(json);
    }



    @Operation(summary = "导出1630成材率数据", description = "根据条件导出数据到Excel")
    @PostMapping("/export1630")
    public void export1630(@Parameter(description = "查询条件") @RequestBody @Valid QueryDTO<TbYieldSearchCondition> queryDTO) {
        allProcessService.export1630(queryDTO);
    }


    @Operation(summary = "导出2150成材率数据", description = "根据条件导出数据到Excel")
    @PostMapping("/export2150")
    public void export2150(@Parameter(description = "查询条件") @RequestBody @Valid QueryDTO<TbYieldSearchCondition> queryDTO) {
        allProcessService2150.export2150(queryDTO);
    }

    @Operation(summary = "导出1870成材率数据", description = "根据条件导出数据到Excel")
    @PostMapping("/export1870")
    public void export1870(@Parameter(description = "查询条件") @RequestBody @Valid QueryDTO<TbYieldSearchCondition> queryDTO) {
        allProcessService1870.export1870(queryDTO);
    }

    @Operation(summary = "导出2280成材率数据", description = "根据条件导出数据到Excel")
    @PostMapping("/export2280")
    public void export2280(@Parameter(description = "查询条件") @RequestBody @Valid QueryDTO<TbYieldSearchCondition> queryDTO) {
        allProcessService2280.export2280(queryDTO);
    }
}
